package hk.edu.polyu.comp.motioncapture.testing;

import com.jacob.activeX.*;
import com.jacob.com.*;

public class CameraEventListener {

	public void FrameAvailable(Variant[] args) {
		System.out.println("FrameAvailable");

		ActiveXComponent camera = new ActiveXComponent(args[0].getDispatch());

		ActiveXComponent frame = new ActiveXComponent(camera.invoke("GetFrame",
				new Variant(0)).getDispatch());
		int pointCount = frame.getPropertyAsInt("Count");
		// System.out.println("Point count: " + pointCount);

		Variant vi = new Variant();
		for (int i = 0; i < pointCount; i++) {
			vi.putInt(i);
			Dispatch point = frame.invoke("Item", vi).getDispatch();

			double x = Dispatch.get(point, "X").getDouble();
			double y = Dispatch.get(point, "Y").getDouble();

			System.out.format("Point: %3.2f, %3.2f\n", x, y);
		}

		frame.invoke("Free");
	}

	public void SwitchChange(Variant[] args) {
		System.out.println("SwitchChange");
	}

}
